package cc.ucanuup.config.security.util;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import cc.ucanuup.config.security.token.MyUsernamePasswordAuthenticationToken;

/**
 * Description: TODO[描述该类概要功能介绍]
 *
 * @author guwenbin
 * @date 2018年2月12日
 * @version 1.0
 */
public class AppUtil {
	public static UserInfo getSrmUserInfo(){
		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		if (auth instanceof MyUsernamePasswordAuthenticationToken) {
			MyUsernamePasswordAuthenticationToken token = 	(MyUsernamePasswordAuthenticationToken) auth;
			UserInfo info = new UserInfo();
			info.setSpCode(token.getSpCode());
			info.setSpId(token.getSpId());
			info.setSpLogin(token.isSpLogin());
			info.setSpName(token.getSpName());
			info.setUserId(token.getUserId());
			info.setUserName(token.getUserName());
			info.setLoginPage(token.getLoginPage());
			info.setUserAccount(token.getPrincipal().toString());
			return info;
		}
		return null;

	}
}
